package com.nanrui.mutualinductor.communicate;

import android.support.annotation.NonNull;

import com.nanrui.mutualinductor.data.DKPacket;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;


public class QueueElement<T extends DKPacket>
        implements Delayed {
    private PacketCallback<T> callback;
    private int count;
    private DKPacket dkPacket;
    private long expires;
    private long timeout;

    public QueueElement(DKPacket paramDKPacket, PacketCallback<T> paramPacketCallback, int paramInt, long paramLong) {
        this.dkPacket = paramDKPacket;
        this.callback = paramPacketCallback;
        this.count = paramInt;
        this.timeout = paramLong;
        this.expires = (System.currentTimeMillis() + paramLong);
    }

    @Override
    public int compareTo(@NonNull Delayed paramDelayed) {
        if (this.expires > ((QueueElement) paramDelayed).expires) {
            return 1;
        }
        if (this.expires < ((QueueElement) paramDelayed).expires) {
            return -1;
        }
        return 0;
    }

    public PacketCallback<T> getCallback() {
        return this.callback;
    }

    public int getCount() {
        return this.count;
    }

    @Override
    public long getDelay(@NonNull TimeUnit paramTimeUnit) {
        return paramTimeUnit.convert(this.expires - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    }

    public DKPacket getDkPacket() {
        return this.dkPacket;
    }

    public void setCount(int paramInt) {
        this.count = paramInt;
        this.expires = (System.currentTimeMillis() + this.timeout);
    }
}
